package mamikeji.liaowa.ui.activity.right.setting;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;

import mamikeji.liaowa.R;
import mamikeji.liaowa.application.MyApplication;
import mamikeji.liaowa.ui.activity.BaseActivity;
import mamikeji.liaowa.ui.activity.FistActivity;
import mamikeji.liaowa.utils.DataCleanManager;
import mamikeji.liaowa.utils.ForPreference;
import mamikeji.liaowa.utils.ForToast;

/**
 * Created by 廉冲-android开发 on 2017/5/9.
 * 设置页面
 */
public class SetActivity extends BaseActivity implements View.OnClickListener {
    private RelativeLayout relativeLayout_set_newmsg, relativeLayout_set_clearcache, relativeLayout_set_about, relativeLayout_set_logout;
    private Dialog dialog_cache;
    public String cacheSize;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set);
        getBase();
        setTitleLeftBtn();
        setTitleName(R.string.set_name);
        init();
        initData();
    }

    /**
     * 加载布局控件
     */
    private void init() {
        relativeLayout_set_newmsg = (RelativeLayout) findViewById(R.id.relativeLayout_set_newmsg);
        relativeLayout_set_clearcache = (RelativeLayout) findViewById(R.id.relativeLayout_set_clearcache);
        relativeLayout_set_about = (RelativeLayout) findViewById(R.id.relativeLayout_set_about);
        relativeLayout_set_logout = (RelativeLayout) findViewById(R.id.relativeLayout_set_logout);
        getDigLog();
        relativeLayout_set_newmsg.setOnClickListener(this);
        relativeLayout_set_clearcache.setOnClickListener(this);
        relativeLayout_set_about.setOnClickListener(this);
        relativeLayout_set_logout.setOnClickListener(this);
    }

    /**
     * 初始化数据
     */
    private void initData() {
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.relativeLayout_set_newmsg:
                MobclickAgent.onEvent(this,"SettingsMessageNotification");//设置-新消息通知
                startActivity(new Intent(SetActivity.this, Set_NewMSGActivity.class));
                break;
            case R.id.relativeLayout_set_clearcache:
                MobclickAgent.onEvent(this,"SettingsClear");//设置-清除缓存
                //获取缓存大小
                try {
                    cacheSize = DataCleanManager.getTotalCacheSize(this);
                    textView_dig_cache_text.setText("共计" + cacheSize + "缓存\n是否清除");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog_cache.show();
                break;
            case R.id.relativeLayout_set_about:
                MobclickAgent.onEvent(this,"SettingsAbout");//设置-关于撩娃
                startActivity(new Intent(SetActivity.this, Set_AboutActivity.class));
                break;
            case R.id.relativeLayout_set_logout:
                ForPreference.clearDate();//清除数据
                startActivity(new Intent(SetActivity.this, FistActivity.class));
                MyApplication.getInstance().exit();
                break;
            case R.id.relativeLayout_set_dig_btnerror:
                dialog_cache.hide();
                break;
            case R.id.relativeLayout_set_dig_query:
                dialog_cache.hide();
                //清除缓存
                DataCleanManager.cleanInternalCache(this);
                DataCleanManager.cleanExternalCache(this);
                ForToast.showToast(R.string.set_clarcache);
                break;
        }
    }

    private TextView textView_dig_cache_text;
    private RelativeLayout relativeLayout_set_dig_btnerror, relativeLayout_set_dig_query;

    private void getDigLog() {
        dialog_cache = new Dialog(SetActivity.this, R.style.DialogLoading);
        View inflate = LayoutInflater.from(SetActivity.this).inflate(R.layout.diglog_set_clearcache, null);
        dialog_cache.setContentView(inflate);

        textView_dig_cache_text = (TextView) inflate.findViewById(R.id.textView_dig_cache_text);
        relativeLayout_set_dig_btnerror = (RelativeLayout) inflate.findViewById(R.id.relativeLayout_set_dig_btnerror);
        relativeLayout_set_dig_query = (RelativeLayout) inflate.findViewById(R.id.relativeLayout_set_dig_query);

        relativeLayout_set_dig_btnerror.setOnClickListener(this);
        relativeLayout_set_dig_query.setOnClickListener(this);
    }
}
